package com.mall.gateway.config;

import com.mall.gateway.limit.IpKeyResolver;
import com.mall.gateway.limit.UriKeyResolver;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author Darren
 * @date 2022-10-21 17:01
 * Description：
 */
@Configuration
public class ResolverConfig {
    /**
     * 根据IP限流
     *
     * @return
     */
    @Primary
    @Bean("ipKeyResolver")
    public KeyResolver ipKeyResolver() {
        return new IpKeyResolver();
    }

    /**
     * 根据URI限流
     *
     * @return
     */
    @Bean("uriKeyResolver")
    public KeyResolver uriKeyResolver() {
        return new UriKeyResolver();
    }
}
